<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>excel export</title>
<script src="shim.min.js"></script>
<script src="xlsx.full.min.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<h4>浏览器excel导出</h4>
<input type="button" value="导出excel" id="export">
<span id="percent">0%</span>
<script>
//http://sheetjs.com/demos/writexlsx.html
//https://www.npmjs.com/package/china-division
//https://github.com/SheetJS/sheetjs
//https://docs.sheetjs.com/docs/demos/data/
//https://github.com/myliang/x-spreadsheet
//https://oss.sheetjs.com/sheetjs/x-spreadsheet
//https://github.com/SheetJS/sheetjs/blob/HEAD/demos/xspreadsheet
//https://www.npmjs.com/package/serve

$(document).ready(function(e) {
	window.data=[];
    $.get('/streets.json',{},function(data){
		window.data=data;
		console.log(data);
	},'json');
});

function process(data,pagesize,page,total_page){
	data.push.apply(data,window.data.slice((page-1)*pagesize,page*pagesize));
	$('#percent').html((page/total_page*100).toFixed(2)+'%');
	
	if(page<total_page){
		setTimeout(function(){
			process(data,pagesize,page+1,total_page);
		},100);
		return;	
	}
	
	var wb = XLSX.utils.book_new(), ws = XLSX.utils.json_to_sheet(data);
	XLSX.utils.book_append_sheet(wb, ws, '数据');
	XLSX.writeFile(wb, 'data.xlsx');
}

$(document).ready(function(e) {
	
    $('#export').click(function(){
		var data=[];
		var pagesize=1000;
		var total_page=Math.ceil(window.data.length/pagesize);
		process(data,pagesize,1,total_page);
	
	});
});
</script>
</body>
</html>
